package XML;

import java.io.File;
import java.io.IOException;

/**
 *
 * @author AlinT
 */
public class DocumentXML {
	private TagXML radacina=null;
	private static boolean hasInstance =false;
	private File f = null;
	private static DocumentXML instance = null;
	
	public DocumentXML(TagXML rad,String filename)
	{
		if (DocumentXML.hasInstance==false){
		this.f=new File(filename);
		this.radacina=rad;
		DocumentXML.hasInstance =true;
		instance=this;
		}else
                {  
                        System.out.println("Instance already exists!"); 
                }
        }
	public void setXMLFile(String filename)
	{
		f=new File(filename);
	}
	public File getXMLFile()
	{
		return f;
	}
	
        public static DocumentXML getInstance()
        {
            if (hasInstance==true)
                return instance;
            return null;
        }
	
	public TagXML getRadacina() {
		return radacina;
	}
	
	public void setRadacina(TagXML radacina) {
		this.radacina = radacina;
	}
	
	public void acceptVisitor(XMLVisitor v)
	{
            try{
		v.visit(radacina);
                try {
			XMLPrinter.getWriter().close();

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
                }
             }catch(Exception e){}
    }
}
